import { baseUrl } from '@/util/config'
import { getToken } from '@/util/auth'


export const updownImage = () => {
	return new Promise((resolve, reject) => {
		uni.chooseImage({
			count: 9, // 支持最多选择9张图片，可根据需要调整
		    success: (chooseImageRes) => {
		        const tempFilePaths = chooseImageRes.tempFilePaths;
				console.log(tempFilePaths)
				const uploadPromises = tempFilePaths.map(filePath => {
					return new Promise((res, rej) => {
						uni.uploadFile({
							url: baseUrl + '/pms/file/upload',
							filePath,
							header: {'Authorization': `Bearer ` + getToken()},
							name: 'file',
							success: (uploadFileRes) => {
								
								let data=JSON.parse(uploadFileRes.data)
							
								res(data.url)
							},
							fail: (err) => {
								rej(err)
							}
						})
					})
				});
				Promise.all(uploadPromises)
					.then(results => resolve(results))
					.catch(err => reject(err));
		    }
		})
	})
}

export const uploadSign = (filePath) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: baseUrl + '/pms/file/upload',
			filePath: filePath,
			header: {'Authorization': `Bearer ` + getToken()},
			name: 'file',
			success: (uploadFileRes) => {
				let data=JSON.parse(uploadFileRes.data)
				
				resolve(data.url)
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}